package com.java.base.exercise.current;

import lombok.SneakyThrows;

import java.util.concurrent.*;

/**
 * @Author RenPu
 * @Date 2024/2/1 10:29
 * @Version 1.0
 * @Description:
 **/
public class CountDownLatchDemoSe {

    private  static CountDownLatch gameMainT=new CountDownLatch(1);

    private  static CountDownLatch clientT=new CountDownLatch(10);

    @SneakyThrows
    public static void main(String[] args) {

        for (int i = 0; i <10 ; i++) {

            new Thread(()->{
                    System.out.println("游戏玩家"+Thread.currentThread().getName()+"已经准备就绪！！！");
                try {
                    gameMainT.await();
                    System.out.println("欢迎"+Thread.currentThread().getName()+"来到王者荣耀！！！！");
                    Thread.sleep(3000);
                    System.out.println("游戏玩家"+Thread.currentThread().getName()+"已被击败！！！！");
                    clientT.countDown();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }).start();

        }

        Thread.sleep(10000);
        System.out.println("比赛正式开始！！！！");
        clientT.countDown();

        gameMainT.countDown();
        Thread.sleep(15000);
        System.out.println("比赛结束！！！！");

    }


}
